# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

CxxFlags := -std=c++0x -g3 -Wall -Wextra -Werror $(CXXFLAGS)
PYTHON := python3.2

INCLUDES := $(wildcard include/* test/*.h)

all: paper test

paper: paper.html
paper.html: render.py toc.js xml/indexpage.xml $(wildcard xml/*)
	$(PYTHON) render.py xml/indexpage.xml > $@
xml/indexpage.xml: Doxyfile $(INCLUDES) $(wildcard test/*)
	doxygen Doxyfile

check: test benchmark
test: $(patsubst %.cc,%.ok,$(wildcard test/*_test.cc))

test/%_run_test: test/%_run_test.cc $(INCLUDES)
	$(CXX) $(CxxFlags) -Iinclude $< -o $@

test/%_run_test.ok: test/%_run_test
	$<
	@touch $@

benchmark: $(patsubst %.cc,%.time,$(wildcard test/*_benchmark.cc))
	@for file in $^; do echo $$file; cat $$file; done

test/%_benchmark: test/%_benchmark.cc $(INCLUDES)
	$(CXX) -O2 $(CxxFlags) -Iinclude $< -o $@

test/%_benchmark.time: test/%_benchmark
	$< > $@


.PHONY: all paper check test
.SECONDARY: # Don't delete intermediate files.
.DELETE_ON_ERROR:
